/*     */ package com.zimbra.cs.mailclient.imap;
/*     */ 
/*     */ import com.zimbra.cs.mailclient.ParseException;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class Body
/*     */ {
/*     */   private String part;
/*     */   private CAtom section;
/*     */   private String[] fieldNames;
/*  42 */   private long origin = -1L;
/*     */   private Object data;
/*     */   
/*     */   public static Body read(ImapInputStream is) throws IOException {
/*  46 */     Body b = new Body();
/*  47 */     b.readBody(is);
/*  48 */     return b;
/*     */   }
/*     */   
/*     */   private void readBody(ImapInputStream is) throws IOException {
/*  52 */     is.skipSpaces();
/*  53 */     is.skipChar('[');
/*  54 */     is.skipSpaces();
/*  55 */     if (is.peekChar() != ']') {
/*  56 */       readSection(is);
/*     */     }
/*  58 */     is.skipSpaces();
/*  59 */     is.skipChar(']');
/*  60 */     is.skipSpaces();
/*  61 */     if (is.match('<')) {
/*  62 */       this.origin = is.readNZNumber();
/*  63 */       is.skipSpaces();
/*  64 */       is.skipChar('>');
/*     */     }
/*  66 */     this.data = is.readFetchData();
/*     */   }
/*     */   
/*     */   private void readSection(ImapInputStream is) throws IOException {
/*  70 */     if (is.isNumber()) {
/*  71 */       this.part = readPart(is);
/*     */     }
/*  73 */     is.skipSpaces();
/*  74 */     if (is.peek() == 93) return;
/*  75 */     Atom sec = is.readAtom();
/*  76 */     this.section = sec.getCAtom();
/*  77 */     switch (this.section) {
/*     */     case HEADER: case TEXT: 
/*     */       break;
/*     */     case HEADER_FIELDS: case HEADER_FIELDS_NOT: 
/*  81 */       is.skipChar(' ');
/*  82 */       is.skipSpaces();
/*  83 */       this.fieldNames = readFieldNames(is);
/*  84 */       break;
/*     */     case MIME: 
/*  86 */       if (this.part == null) {
/*  87 */         throw new ParseException("BODY[MIME] response missing section part");
/*     */       }
/*     */       
/*     */       break;
/*     */     default: 
/*  92 */       throw new ParseException("Invalid BODY section type: " + sec);
/*     */     }
/*     */   }
/*     */   
/*     */   private static String readPart(ImapInputStream is) throws IOException {
/*  97 */     StringBuffer sb = new StringBuffer();
/*     */     for (;;) {
/*  99 */       sb.append(is.readNZNumber());
/* 100 */       if (is.peek() == 93) break;
/* 101 */       is.skipChar('.');
/* 102 */       if (!is.isNumber()) break;
/* 103 */       sb.append('.');
/*     */     }
/* 105 */     return sb.toString();
/*     */   }
/*     */   
/*     */   private static String[] readFieldNames(ImapInputStream is) throws IOException
/*     */   {
/* 110 */     ArrayList<String> names = new ArrayList();
/* 111 */     is.skipChar('(');
/* 112 */     is.skipSpaces();
/* 113 */     while (!is.match(')')) {
/* 114 */       names.add(is.readAString());
/* 115 */       is.skipSpaces();
/*     */     }
/* 117 */     return (String[])names.toArray(new String[names.size()]);
/*     */   }
/*     */   
/* 120 */   public String getPart() { return this.part; }
/* 121 */   public CAtom getSection() { return this.section; }
/* 122 */   public String[] getFieldNames() { return this.fieldNames; }
/* 123 */   public long getOrigin() { return this.origin; }
/* 124 */   public Object getData() { return this.data; }
/*     */   
/*     */   public ImapData getImapData() {
/* 127 */     if ((this.data != null) && (!(this.data instanceof ImapData))) {
/* 128 */       throw new UnsupportedOperationException();
/*     */     }
/* 130 */     return (ImapData)this.data;
/*     */   }
/*     */   
/*     */   public void dispose() {
/* 134 */     if ((this.data instanceof ImapData)) {
/* 135 */       ((ImapData)this.data).dispose();
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/imap/Body.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */